<?php

/**
 * @author Djordje Zeljic
 * Date: May 28, 2010 10:35:51 AM
 */
class invoice_m extends Model {

    function invoice_m () {
        parent::Model();
    }// construct of invoice_m

    function create(){

    }

    function read($id, $cascaderead = FALSE){
        if($cascaderead == TRUE){
            return $this->db->select('*')
                    ->from('invoices')
                    ->join('invoicestatus','invoicestatus.invoiceNumber = invoices.invoiceNumber','left')
                    ->join('orders','orders.id = invoices.orderid','left')
                    ->join('financisaltransaction','financisaltransaction.invoicenumber = invoices.invoicenumber')
                    ->join('invoicelineitems','invoicelineitems.invoiceNumber = invoices.invoicenumber')
                    ->where('invoicenumber',$id)
                    ->get()
                    ->row_array();
        }else{
            return $this->db->where('invoiceNumber',$id)->get('invoices')->row_array();
        }
    }

    function readAll($cascaderead = FALSE){
        if($cascaderead == TRUE){
            return $this->db->select('*')
                    ->from('invoices')
                    ->join('invoicestatus','invoicestatus.invoiceNumber = invoices.invoiceNumber','left')
                    ->join('orders','orders.id = invoices.orderid','left')
                    ->join('financisaltransaction','financisaltransaction.invoicenumber = invoices.invoicenumber','left')
                    ->join('invoicelineitems','invoicelineitems.invoiceNumber = invoices.invoicenumber','left')
                    ->get()
                    ->row_array();
        }else{
            return $this->db->order_by('id','desc')
                    ->get('invoices')
                    ->result_array();
        }
    }

    function update(){

    }

    function delete(){

    }
    
}
?>